const { contextBridge, ipcRenderer,webUtils } = require('electron')

contextBridge.exposeInMainWorld('electron', {
  getFilePath:(file)=>{
    return webUtils.getPathForFile(file)
  },

  localIp: () => ipcRenderer.invoke('localIp'),
  connectChat: () => ipcRenderer.invoke('connectChat'),
  disconnectChat: () => ipcRenderer.invoke('disconnectChat'),

  openView: ()=> ipcRenderer.invoke('open-file-box')

})

contextBridge.exposeInMainWorld('chat', {
  onReceive: (callback) => ipcRenderer.on('chat-receive', (_, value)=>callback(value)),

  onStdout: (callback) => ipcRenderer.on('file-stdout', (_, value)=>callback(value)),

  openSend: (remoteIp) => ipcRenderer.invoke('chat-openSend', remoteIp),

  updSend: (message, remoteIp) => ipcRenderer.invoke('chat-updSend', message , remoteIp),
  tcpSend: (id,filepath) => ipcRenderer.invoke('file-send', id,filepath),

  open: (remoteIp) => ipcRenderer.invoke('file-open', remoteIp),
});

